package com.kou.backend.controller.user;

import com.kou.backend.api.user.IUserClient;
import com.kou.backend.request.user.SaveUserReqDTO;
import com.kou.backend.resposne.ResultResponse;
import com.kou.backend.service.UserInfoService;
import com.kou.backend.util.JsonUtils;
import jakarta.annotation.Resource;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author: Kou
 * @since: 2023/8/29 19:44
 */
@RestController
public class UserController implements IUserClient {
    @Resource
    private UserInfoService userInfoService;

    @Override
    public ResultResponse<Object> queryUser() {
        return null;
    }

    @Override
    public ResultResponse<Object> detailUser() {
        Object parse = JsonUtils.parseJSONObject("{\"msg\":\"success\",\"code\":\"0\",\"permissions\":[\"*:*:*\"],\"roles\":[\"admin\"],\"user\":{\"createBy\":\"admin\",\"createTime\":\"2023-04-23 16:11:38\",\"updateBy\":null,\"updateTime\":null,\"remark\":\"管理员\",\"userId\":1,\"deptId\":103,\"userName\":\"admin\",\"nickName\":\"若依\",\"email\":\"ry@163.com\",\"phonenumber\":\"15888888888\",\"sex\":\"1\",\"avatar\":\"\",\"password\":\"$2a$10$7JB720yubVSZvUI0rEqK/.VqGOZTH.ulu33dHOiBE8ByOhJIrdAu2\",\"status\":\"0\",\"delFlag\":\"0\",\"loginIp\":\"117.133.11.5\",\"loginDate\":\"2023-09-02T09:10:10.000+08:00\",\"dept\":{\"createBy\":null,\"createTime\":null,\"updateBy\":null,\"updateTime\":null,\"remark\":null,\"deptId\":103,\"parentId\":101,\"ancestors\":\"0,100,101\",\"deptName\":\"研发部门\",\"orderNum\":1,\"leader\":\"若依\",\"phone\":null,\"email\":null,\"status\":\"0\",\"delFlag\":null,\"parentName\":null,\"children\":[]},\"roles\":[{\"createBy\":null,\"createTime\":null,\"updateBy\":null,\"updateTime\":null,\"remark\":null,\"roleId\":1,\"roleName\":\"超级管理员\",\"roleKey\":\"admin\",\"roleSort\":1,\"dataScope\":\"1\",\"menuCheckStrictly\":false,\"deptCheckStrictly\":false,\"status\":\"0\",\"delFlag\":null,\"flag\":false,\"menuIds\":null,\"deptIds\":null,\"permissions\":null,\"admin\":true}],\"roleIds\":null,\"postIds\":null,\"roleId\":null,\"admin\":true}}");

        return ResultResponse.success(parse);
    }

    @Override
    @PreAuthorize("hasAnyAuthority('all')")
    public ResultResponse<Object> saveUser(SaveUserReqDTO saveUserReqDTO) {
        userInfoService.saveUser(saveUserReqDTO);
        return ResultResponse.success();
    }

    @Override
    public ResultResponse<Object> deleteUser() {
        return null;
    }
}
